package com.example.test;

import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;

public class MainActivity extends AppCompatActivity {

    private ImageView ivSolid;
    private ImageView ivSolid_2;
    private ImageView iv16;
    private ImageView iv16_2;
    private ImageView iv32;
    private ImageView iv32_2;
    private ImageView iv64;
    private ImageView iv64_2;
    private AnimatorSet animatorSet;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ivSolid = findViewById(R.id.iv_solid);
        ivSolid_2 = findViewById(R.id.iv_solid_2);
        iv16 = findViewById(R.id.iv_16);
        iv16_2 = findViewById(R.id.iv_16_2);
        iv32 = findViewById(R.id.iv_32);
        iv32_2 = findViewById(R.id.iv_32_2);
        iv64 = findViewById(R.id.iv_64);
        iv64_2 = findViewById(R.id.iv_64_2);

        ivSolid_2.setVisibility(View.GONE);
        iv16_2.setVisibility(View.GONE);
        iv32_2.setVisibility(View.GONE);
        iv64_2.setVisibility(View.GONE);
        initAnim();

    }

    @SuppressLint("CheckResult")
    private void initAnim() {


        go(ivSolid,2000);
        go(iv16,2000);
        go(iv32,2000);
        go(iv64,2000);



    }

    private void go(ImageView iv, int duration) {
        ObjectAnimator animatorX = ObjectAnimator.ofFloat(iv, "scaleX", 0.8f, 1.2f, 1.5f);
        ObjectAnimator animatorY = ObjectAnimator.ofFloat(iv, "scaleY", 0.8f, 1.2f, 1.5f);
        ObjectAnimator animatorZ = ObjectAnimator.ofFloat(iv, "alpha", 1f, 0.8f, 0.5f, 0f);

        animatorX.setDuration(duration);
        animatorX.setRepeatCount(-1);

        animatorY.setDuration(duration);
        animatorY.setRepeatCount(-1);

        animatorZ.setDuration(duration);
        animatorZ.setRepeatCount(-1);
        animatorSet = new AnimatorSet();
        animatorSet.playTogether(animatorX, animatorY, animatorZ);
        animatorSet.start();


    }


}
